using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace Codex
{
    public partial class OptionsForm : Form
    {
        Font treePaneFont, textPaneFont;
        Color treePaneBackColor, treePaneFontColor, textPaneBackColor, textPaneFontColor;
        string blogAuthName, blogUserName, blogPassword, blogID;

        Boolean changeTreePaneBackColor, changeTreePaneFontColor,
            changeTextPaneBackColor, changeTextPaneFontColor,
            changeTreePaneFont, changeTextPaneFont;

        public OptionsForm()
        {
            InitializeComponent();

            nameTextBox.Text = Properties.Settings.Default.blogAuthName;
            addressTextBox.Text = Properties.Settings.Default.blogUserName;
            passwordTextBox.Text = Properties.Settings.Default.blogPassword;
            blogIDTextBox.Text = Properties.Settings.Default.blogID;
        }


        private void comboBox1_SelectedValueChanged(object sender, EventArgs e)
        {
            fontDialog1.ShowDialog();

            switch (comboBox1.SelectedText)
            {
                case "Tree Pane":
                    treePaneFont = fontDialog1.Font;
                    changeTreePaneFont = true;
                    break;
                case "Entry Pane":
                    textPaneFont = fontDialog1.Font;
                    changeTextPaneFont = true;
                    break;
            }
        }

        private void comboBox2_SelectedValueChanged(object sender, EventArgs e)
        {
            colorDialog1.ShowDialog();

            switch (comboBox2.SelectedText)
            {
                case "Tree Pane Background":
                    treePaneBackColor = colorDialog1.Color;
                    changeTreePaneBackColor = true;
                    break;
                case "Tree Pane Text":
                    treePaneFontColor = colorDialog1.Color;
                    changeTreePaneFontColor = true;
                    break;
                case "Entry Pane Background":
                    textPaneBackColor = colorDialog1.Color;
                    changeTextPaneBackColor = true;
                    break;
                case "Entry Pane Text":
                    textPaneFontColor = colorDialog1.Color;
                    changeTextPaneFontColor = true;
                    break;
            }
        }



        private void cancelBtn_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void applyBtn_Click(object sender, EventArgs e)
        {
            applySettings();
        }

        private void applySettings()
        {
            if (treePaneBackColor != null && changeTreePaneBackColor)
                Properties.Settings.Default.TreePaneBackColor = treePaneBackColor;
            if (treePaneFontColor != null && changeTreePaneFontColor)
                Properties.Settings.Default.TreePaneFontColor = treePaneFontColor;
            if (textPaneBackColor != null && changeTextPaneBackColor)
                Properties.Settings.Default.TextPaneBackColor = textPaneBackColor;
            if (textPaneFontColor != null && changeTextPaneFontColor)
                Properties.Settings.Default.TextPaneBackColor = textPaneFontColor;

            if (treePaneFont != null && changeTreePaneFont)
                Properties.Settings.Default.TreePaneFont = treePaneFont;
            if (textPaneFont != null && changeTextPaneFont)
                Properties.Settings.Default.TextPaneFont = textPaneFont;

            if (!nameTextBox.Text.Equals(""))
                Properties.Settings.Default.blogAuthName = nameTextBox.Text;
            if (!addressTextBox.Text.Equals(""))
                Properties.Settings.Default.blogUserName = addressTextBox.Text;
            if (!passwordTextBox.Text.Equals(""))
                Properties.Settings.Default.blogPassword = passwordTextBox.Text;
            if (!blogIDTextBox.Text.Equals(""))
                Properties.Settings.Default.blogID = blogIDTextBox.Text;
        }

        private void linkLabel1_Click(object sender, EventArgs e)
        {
            System.Diagnostics.Process.Start("IExplore", "http://help.blogger.com/bin/answer.py?hl=en&answer=42191");
        }

        private void button1_Click(object sender, EventArgs e)
        {
            applySettings();
            this.Close();
        }
    }
}